package com.xii.service;


import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xii.entity.PageResult;
import com.xii.entity.QueryPageBean;
import com.xii.mapper.SetmealMapper;
import com.xii.pojo.Setmeal;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Service
public class SetmealServiceImpl implements SetmealService {

    @Autowired
    private SetmealMapper setmealMapper;

    @Override
    public void add(Integer[] checkgroupIds, Setmeal setmeal) {
        //1、添加套餐
        setmealMapper.addSetmeal(setmeal);
        //2、返回主键 新增添加关联表
        Integer setmealId = setmeal.getId();
        for (Integer checkgroupId : checkgroupIds) {
            setmealMapper.addSetmealGroupBySetmealId(setmealId,checkgroupId);
        }

    }

    /**
     * 分页查询
     * @param pageBean
     * @return
     */
    @Override
    public PageResult findPage(QueryPageBean pageBean) {
        //当前页   每页的记录数
        PageHelper.startPage(pageBean.getCurrentPage(),pageBean.getPageSize());
        List<Setmeal> setmealList = setmealMapper.findPage(pageBean.getQueryString());
        PageInfo<Setmeal> setmealPageInfo = new PageInfo<>(setmealList);
        return new PageResult(setmealPageInfo.getTotal(),setmealPageInfo.getList());
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<Setmeal> findAll() {
        return setmealMapper.findAll();
    }

    @Override
    public Setmeal findById(Integer id) {
        return setmealMapper.findById(id);
    }

    /**
     * 套餐报表
     * @return
     */
    @Override
    public List<Map<String, Object>> findSetmealCount() {
        return setmealMapper.findSetmealCount();
    }

}
